home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / exee.c < prev    next >
C/C++ Source or Header  |  1993-06-19  |  37KB  |  1,443 lines

  1. /*****************************************************************************
  2.  
  3.     ExeE()
  4.  
  5.     This function executes a E command.
  6.  
  7.     EA        Select secondary output stream
  8.     EBfilespec$    Open file for input and output
  9.     :EBfilespec$    EB, return status
  10.     EC        Close out (copy in to out and close)
  11.     ED        Edit mode flag
  12.     EE        Escape surrogate character
  13.     EF        Close output file
  14.     EG        Close out and exit, run last COMPIL class command
  15.     :EGcmd args$    Performs operating system function
  16.     :EGtext$    Close out and exit, run "text"
  17.     EH        Help level flag
  18.     EI        Close current indirect command file
  19.     EIfilespec$    Open indirect command file
  20.     m,nEJ        Set environment characteristics
  21.     nEJ        Return environment characteristics
  22.     EK        Kill output file
  23.     ELfilespec$    Open log file
  24.     mEM        Position mag tape
  25.     EN        Wildcard lookup
  26.     :EN        EN, return status
  27.     ENfilespec$    Preset wildcard lookup
  28.     EO        Version of TECO
  29.     nEO        Set TECO to function as version n
  30.     EP        Select secondary output stream
  31.     EQqfilespec$    Read file into Q-register q
  32.     ER        Select primary input stream
  33.     ERfilespec$    Open input file
  34.     :ERfilespec$    ER, return status
  35.     ES        Search verification flag
  36.     ET        Type out control flag
  37.     EU        Case flagging flag
  38.     EV        Edit verify flag
  39.     EWfilespec$    Open output file
  40.     EW        Select primary output stream
  41.     EX        Close out and exit
  42.     EY        Read without yank protection
  43.     EZ        System-dependent mode control flags
  44.     E%qfilespec$    Write Q-register q into a file
  45.     nE_        Search without yank protection
  46.  
  47. *****************************************************************************/
  48.  
  49. #include "zport.h"        /* define portability identifiers */
  50. #include "tecoc.h"        /* define general identifiers */
  51. #include "defext.h"        /* define external global variables */
  52. #include "chmacs.h"        /* define character processing macros */
  53. #include "dchars.h"        /* define identifiers for characters */
  54. #include "deferr.h"        /* define identifiers for error messages */
  55.  
  56. #if USE_PROTOTYPES
  57. static DEFAULT DoEI(DEFAULT IfIndx);
  58. static DEFAULT ExeEA(void);
  59. static DEFAULT ExeEB(void);
  60. static DEFAULT ExeEC(void);
  61. static DEFAULT ExeED(void);
  62. static DEFAULT ExeEF(void);
  63. static DEFAULT ExeEG(void);
  64. static DEFAULT ExeEH(void);
  65. static DEFAULT ExeEI(void);
  66. static DEFAULT ExeEK(void);
  67. static DEFAULT ExeEN(void);
  68. static DEFAULT ExeEO(void);
  69. static DEFAULT ExeEP(void);
  70. static DEFAULT ExeEPr(void);
  71. static DEFAULT ExeEQ(void);
  72. static DEFAULT ExeER(void);
  73. static DEFAULT ExeES(void);
  74. static DEFAULT ExeET(void);
  75. static DEFAULT ExeEU(void);
  76. static DEFAULT ExeEUn(void);
  77. static DEFAULT ExeEV(void);
  78. static DEFAULT ExeEW(void);
  79. static DEFAULT ExeEX(void);
  80. static DEFAULT ExeEZ(void);
  81. static DEFAULT GetWha(charptr TxtPtr, ptrdiff_t TxtLen);
  82. static DEFAULT OpnEI(DEFAULT EInd);
  83. static DEFAULT OpnInp(DEFAULT IfIndx, BOOLEAN EIFile, BOOLEAN RepFNF);
  84. static DEFAULT OpnOut(DEFAULT OfIndx, BOOLEAN RepErr);
  85. static DEFAULT ReadEI(DEFAULT IfIndx, charptr *ZBfPtr, charptr *EscPtr);
  86. #endif
  87.  
  88. charptr ZBfBeg;
  89. charptr ZBfEnd;
  90. charptr ZBfRdP;        /* pointer where to start reading into ZBf */
  91.  
  92. /*****************************************************************************
  93.  
  94.     OpnInp()
  95.  
  96.     This function opens an input file.  The name of the file is pointed
  97. to by FBfBeg.  FBfPtr points to the character following the last character of
  98. the file name.
  99.  
  100. *****************************************************************************/
  101.  
  102. static DEFAULT OpnInp(IfIndx, EIFile, RepFNF)
  103. DEFAULT    IfIndx;                /* output file indicator */
  104. BOOLEAN    EIFile;                /* is it a macro file? */
  105. BOOLEAN RepFNF;                /* report "file not found" error? */
  106. {
  107.     DEFAULT status;
  108.  
  109.     DBGFEN(2,"OpnInp",NULL);
  110.  
  111.     ZIClos(IfIndx);            /* close input file, if any */
  112.  
  113.     status = ZOpInp(IfIndx, EIFile, RepFNF);
  114.     if (status != SUCCESS) {
  115.     if (!RepFNF && (status == FILENF)) {
  116.         DBGFEX(2,DbgFNm,"FILENF");
  117.         return FILENF;
  118.     }
  119.     ErrPSt(ERR_UFI, FBfBeg, FBfPtr);
  120.     DBGFEX(2,DbgFNm,"status");
  121.     return status;
  122.     }
  123.  
  124.     IsOpnI[IfIndx] = TRUE;        /* mark the file as open */
  125.     IsEofI[IfIndx] = FALSE;        /* end-of-file indicator */
  126.  
  127.     DBGFEX(2,DbgFNm,"SUCCESS");
  128.     return SUCCESS;
  129. }
  130.  
  131. /*****************************************************************************
  132.  
  133.     OpnOut()
  134.  
  135.     This function creates and opens an output file.  The name of the file
  136. to be created is pointed to by FBfBeg.  FBfPtr points to the character
  137. following the last character of the file name.
  138.  
  139. *****************************************************************************/
  140.  
  141.  
  142. static DEFAULT OpnOut(OfIndx, RepErr)
  143. DEFAULT    OfIndx;                /* output file indicator */
  144. BOOLEAN RepErr;                /* report errors? */
  145. {
  146.     DBGFEN(2,"OpnOut",NULL);
  147.  
  148.     if (IsOpnO[OfIndx]) {        /* if output file is open */
  149.         ErrMsg(ERR_OFO);    /* OFO = output file already open */
  150.         DBGFEX(2,DbgFNm,"FAILURE");
  151.         return FAILURE;
  152.     }
  153.  
  154.     if (ZOpOut(OfIndx, RepErr) == FAILURE) {
  155.         if (RepErr) {
  156.             ErrPSt(ERR_UFO, FBfBeg, FBfPtr);
  157.         }
  158.         DBGFEX(2,DbgFNm,"FAILURE");
  159.         return FAILURE;
  160.     }
  161.  
  162.     IsOpnO[OfIndx] = TRUE;
  163.  
  164.     DBGFEX(2,DbgFNm,"SUCCESS");
  165.     return SUCCESS;
  166. }
  167.  
  168. /*****************************************************************************
  169.  
  170.     ExeEA()
  171.  
  172.     This function executes an EA command.
  173.  
  174.     EA    Select secondary output stream
  175.  
  176. *****************************************************************************/
  177.  
  178. static DEFAULT ExeEA()            /* execute an EA command */
  179. {
  180.     DBGFEN(1,"ExeEA",NULL);
  181.  
  182.     CurOut = SOUTFL;
  183.     CmdMod = '\0';            /* clear modifiers flags */
  184.     EStTop = EStBot;        /* clear expression stack */
  185.  
  186.     DBGFEX(1,DbgFNm,"SUCCESS");
  187.     return SUCCESS;
  188. }
  189.  
  190. /*****************************************************************************
  191.  
  192.     ExeEB()
  193.  
  194.     This function executes an EB command.
  195.  
  196.     EBfilespec$    Open file for input and output
  197.     :EBfilespec$    EB, return status
  198.  
  199. *****************************************************************************/
  200.  
  201. static DEFAULT ExeEB()            /* execute an EB command */
  202. {
  203.     BOOLEAN    RepFNF;            /* report "file not found" ? */
  204.     DEFAULT    status;            /* OpnInp() status */
  205.  
  206.     DBGFEN(1,"ExeEB",NULL);
  207.  
  208.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  209.         DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  210.         return FAILURE;
  211.     }
  212.  
  213.     RepFNF = !(CmdMod & COLON);        /* report file not found? */
  214.     CmdMod = '\0';                /* clear modifiers flags */
  215.     status = OpnInp(CurInp, FALSE, RepFNF);    /* open input file */
  216.     if (status != SUCCESS) {
  217.         if (status == FILENF) {
  218.             if (!RepFNF) {        /* if it's :EB */
  219.                 DBGFEX(1,DbgFNm,"PushEx(0)");
  220.                 return PushEx(0L,OPERAND);
  221.             }
  222.         }
  223.         DBGFEX(1,DbgFNm,"FAILURE, OpnInp() failed");
  224.         return FAILURE;
  225.     }
  226.  
  227.     ZMKOFN();                /* kludge for VMS filenames */
  228.  
  229.     if (OpnOut(CurOut, RepFNF) == FAILURE) {/* open output file */
  230. #if DEBUGGING
  231.         sprintf(DbgSBf,"%s, OpnOut() failed",
  232.             (RepFNF) ? "FAILURE" : "PushEx(0)");
  233.         DbgFEx(1,DbgFNm,DbgSBf);
  234. #endif
  235.         return (RepFNF) ? FAILURE : PushEx(0L,OPERAND);
  236.     }
  237.  
  238.     if (!RepFNF) {                /* if it's :EB */
  239.         DBGFEX(1,DbgFNm,"PushEx(-1)");
  240.         return PushEx(-1L,OPERAND);
  241.     }
  242.  
  243.     EStTop = EStBot;            /* clear expression stack */
  244.     DBGFEX(1,DbgFNm,"SUCCESS");
  245.     return SUCCESS;
  246. }
  247.  
  248. /*****************************************************************************
  249.  
  250.     ExeEC()
  251.  
  252.     This function executes an EC command.
  253.  
  254.     EC    Close out (copy in to out and close)
  255.  
  256. *****************************************************************************/
  257.  
  258. static DEFAULT ExeEC()            /* execute an EC command */
  259. {
  260.     DBGFEN(1,"ExeEC",NULL);
  261.  
  262.     if (EStTop > EStBot) {            /* if numeric argument */
  263.         if (GetNmA() == FAILURE) {    /* get numeric argument */
  264.             DBGFEX(1,DbgFNm,"FAILURE, GetNmA() failed");
  265.             return FAILURE;
  266.         }
  267.  
  268. /* ??? */    ZDspBf("memory expand as per page 84\r\n", 29);
  269.         CmdMod = '\0';            /* clear modifiers flags */
  270.  
  271.         DBGFEX(1,DbgFNm,"SUCCESS");
  272.         return SUCCESS;
  273.     }
  274.  
  275.     if (IsOpnO[CurOut]) {
  276.  
  277. /*
  278.  * if there's text in the edit buffer,  or if the form feed flag indicates
  279.  * that the current page needs to be output,  call WrPage to write the page,
  280.  * then clear the edit buffer.
  281.  */
  282.  
  283.     if ((GapBeg > EBfBeg) || (GapEnd < EBfEnd) || FFPage) {
  284.         if (WrPage(CurOut, EBfBeg, EBfEnd, FFPage) == FAILURE) {
  285.             DBGFEX(1,DbgFNm,"FAILURE, WrPage() failed");
  286.             return FAILURE;
  287.         }
  288.         GapBeg = EBfBeg;        /* clear the... */
  289.         GapEnd = EBfEnd;        /*   ...edit buffer */
  290.     }
  291.  
  292. /*
  293.  * Move the remainder of the current input file, if any, to the currenti
  294.  * output file.
  295.  */
  296.  
  297.     if (IsOpnI[CurInp]) {            /* if input file is open */
  298.         while (!IsEofI[CurInp]) {    /* while not end-of-file */
  299.             if (RdPage() == FAILURE) {    /* read a page */
  300.                 DBGFEX(1,DbgFNm,"FAILURE, RdPage() failed");
  301.                 return FAILURE;
  302.             }
  303.             if (WrPage(CurOut, EBfBeg, EBfEnd, FFPage) == FAILURE) {
  304.                 DBGFEX(1,DbgFNm,"FAILURE, WrPage() failed");
  305.                 return FAILURE;
  306.             }
  307.             GapBeg = EBfBeg;    /* clear the... */
  308.             GapEnd = EBfEnd;    /*   ...edit buffer */
  309.         }
  310.     }
  311.     }
  312.  
  313.     ZIClos(PINPFL);        /* close primary input file */
  314.     ZIClos(SINPFL);        /* close secondary input file */
  315.     ZOClos(POUTFL);        /* close primary output file */
  316.     ZOClos(SOUTFL);        /* close secondary output file */
  317.  
  318.     CmdMod = '\0';        /* clear modifiers flag */
  319.     DBGFEX(1,DbgFNm,"SUCCESS");
  320.     return SUCCESS;
  321. }
  322.  
  323. /*****************************************************************************
  324.  
  325.     ExeED()
  326.  
  327.     This function executes an ED command.
  328.  
  329.     ED        Edit mode flag
  330.  
  331. *****************************************************************************/
  332.  
  333. static DEFAULT ExeED()            /* execute an ED command */
  334. {
  335.     DBGFEN(1,"ExeED",NULL);
  336.     DBGFEX(1,DbgFNm,"DoFlag(&EdFlag)");
  337.     return DoFlag(&EdFlag);
  338. }
  339.  
  340. /*****************************************************************************
  341.  
  342.     ExeEF()
  343.  
  344.     This function executes an EF command.
  345.  
  346.     EF        Close output file
  347.  
  348. *****************************************************************************/
  349.  
  350. static DEFAULT ExeEF()            /* execute an EF command */
  351. {
  352.     DBGFEN(1,"ExeEF",NULL);
  353.  
  354.     ZOClos(CurOut);            /* close output file */
  355.     CmdMod = '\0';            /* clear modifiers flags */
  356.     EStTop = EStBot;        /* clear expression stack */
  357.  
  358.     DBGFEX(1,DbgFNm,"SUCCESS");
  359.     return SUCCESS;
  360. }
  361.  
  362. /*****************************************************************************
  363.  
  364.     ExeEG()
  365.  
  366.     This function implements the EG command.  If the EG command is not
  367. colon modified,  it terminates TECO and passes a command line to the command
  368. line interpreter.
  369.  
  370.     EG        Close out and exit
  371.     EGtext$        Close out and exit, execute "text" command
  372.  
  373. If the EG command is colon modified,  then it implements one of the "special
  374. functions" as follows:
  375.  
  376.     :EGINI$        gets, sets or clears the initialization file name
  377.     :EGLIB$        gets, sets or clears the macro library directory
  378.     :EGMEM$        gets, sets or clears the file name memory
  379.     :EGVTE$        gets, sets or clears the video macro file name
  380.  
  381. other, system-dependent functions may be defined.  See the ZClnEG function.
  382.  
  383. *****************************************************************************/
  384.  
  385. static DEFAULT GetWha(TxtPtr, TxtLen)    /* get "what to operate on" */
  386. charptr TxtPtr;                /* string to parse */
  387. ptrdiff_t TxtLen;            /* length of string */
  388. {
  389.     if (TxtLen >= 3) {            /* it's long enough */
  390.         switch(To_Upper(*TxtPtr)) {
  391.         case 'I':            /* INI (init macro) */
  392.             TxtPtr++;
  393.             if (To_Upper(*TxtPtr) == 'N') {
  394.                 ++TxtPtr;
  395.                 if (To_Upper(*TxtPtr) == 'I') {
  396.                     return EG_INI;
  397.                 }
  398.             }
  399.             break;
  400.  
  401.         case 'L':            /* LIB (macro directory) */
  402.             TxtPtr++;
  403.             if (To_Upper(*TxtPtr) == 'I') {
  404.                 TxtPtr++;
  405.                 if (To_Upper(*TxtPtr) == 'B') {
  406.                     return EG_LIB;
  407.                 }
  408.             }
  409.             break;
  410.  
  411.         case 'M':            /* MEM (filename memory) */
  412.             TxtPtr++;
  413.             if (To_Upper(*TxtPtr) == 'E') {
  414.                 TxtPtr++;
  415.                 if (To_Upper(*TxtPtr) == 'M') {
  416.                     return EG_MEM;
  417.                 }
  418.             }
  419.             break;
  420.  
  421.         case 'V':            /* VTE (vtedit macro) */
  422.             TxtPtr++;
  423.             if (To_Upper(*TxtPtr) == 'T') {
  424.                 TxtPtr++;
  425.                 if (To_Upper(*TxtPtr) == 'E') {
  426.                     return EG_VTE;
  427.                 }
  428.             }
  429.             break;
  430.  
  431.         default:
  432.             break;
  433.         }
  434.     }
  435.  
  436.     return EG_OTHER;
  437. }
  438.  
  439. #define GBFSIZE 256
  440.  
  441. static DEFAULT ExeEG()        /* perform operating system function */
  442. {
  443.     DEFAULT EGWhat;        /* what to operate on: INI, VTE, etc. */
  444.     unsigned char GBfBeg[GBFSIZE];
  445.     charptr GBfPtr;
  446.     ptrdiff_t GBfLen;
  447.  
  448.     DBGFEN(1,"ExeEG",NULL);
  449.  
  450.     if (BldStr(GBfBeg, GBfBeg+GBFSIZE-2, &GBfPtr) == FAILURE) {
  451.     DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  452.     return FAILURE;
  453.     }
  454.  
  455.     GBfLen = GBfPtr - GBfBeg;
  456.     if (CmdMod & COLON) {            /* if it's :EG */
  457.         DEFAULT EGOper = GET_VAL;        /* get, set or clear */
  458.     charptr TmpPtr;
  459.     CmdMod &= ~COLON;            /* clear colon flag */
  460.     EGWhat = GetWha(GBfBeg,GBfLen);
  461.     TmpPtr = (charptr)GBfBeg;
  462.     if (EGWhat != EG_OTHER) {
  463.         if (GBfLen == 4) {            /* if it's "clear" */
  464.             if (*(TmpPtr+3) != ' ') {
  465.             DBGFEX(1,DbgFNm,"PushEx(0)");
  466.             return PushEx(0L,OPERAND);
  467.         }
  468.         EGOper = CLEAR_VAL;
  469.         } else if (GBfLen != 3) {        /* it it's not "get" */
  470.             EGOper = SET_VAL;
  471.         TmpPtr += 4;
  472.         }
  473.         }
  474.     *GBfPtr = '\0';
  475.     DBGFEX(1,DbgFNm,"PushEx(ZClnEG())");
  476.     return PushEx(ZClnEG(EGWhat,EGOper,TmpPtr),OPERAND);
  477.     }
  478.  
  479.     if (ExeEC() == FAILURE) {            /* do an EC command */
  480.     DBGFEX(1,DbgFNm,"FAILURE, ExeEC() failed");
  481.     return FAILURE;
  482.     }
  483.  
  484.     if (GBfLen == 0) {                /* if it was EC$ */
  485.     TAbort(EXIT_SUCCESS);            /* just exit TECO-C */
  486.     }
  487.  
  488.     ZDoCmd();                    /* exit with a command */
  489.     DBGFEX(1,DbgFNm,"SUCCESS");        /* we should never reach this */
  490.     return SUCCESS;
  491. }
  492.  
  493. /*****************************************************************************
  494.  
  495.     ExeEH()
  496.  
  497.     This function executes an EH command.
  498.  
  499.     EH        Help level flag
  500.  
  501. *****************************************************************************/
  502.  
  503. static DEFAULT ExeEH()            /* execute an EH command */
  504. {
  505.     DBGFEN(1,"ExeEH",NULL);
  506.     DBGFEX(1,DbgFNm,"DoFlag()");
  507.     return DoFlag(&EhFlag);
  508. }
  509.  
  510. /*****************************************************************************
  511.  
  512.     ReadEI()
  513.  
  514.     This function reads an EI file.  It is passed an index for the file
  515. data block of the open EI file,  and a buffer.  It reads the contents of the
  516. file into the buffer,  stopping when a double ESCAPE or end-of-file is
  517. encountered.
  518.  
  519. *****************************************************************************/
  520.  
  521. static DEFAULT ReadEI(IfIndx, ZBfPtr, EscPtr)
  522. DEFAULT    IfIndx;        /* index into IFiles array */
  523. charptr    *ZBfPtr;    /* returned ptr to end of EI string (+1) */
  524. charptr *EscPtr;    /* returned ptr to $$ in EI string  (+1) */
  525. {
  526.     DEFAULT        line_len;
  527.     charptr        NewBuf;
  528.     SIZE_T        NewSiz;
  529.     BOOLEAN        previous_char_was_escape;
  530.     charptr        TmpPtr;
  531.  
  532. #if DEBUGGING
  533.     static char *DbgFNm = "ReadEI";
  534.     sprintf(DbgSBf,"ZBfBeg = %ld, ZBfEnd = %ld",
  535.         Zcp2ul(ZBfBeg), Zcp2ul(ZBfEnd));
  536.     DbgFEn(1,DbgFNm,DbgSBf);
  537. #endif
  538.  
  539.     FOREVER {
  540.  
  541. /*
  542.  * potentially reallocate ZBf
  543.  */
  544.  
  545.         if ((ZBfEnd - ZBfRdP) < ZBFMIN) {
  546.             NewSiz = (ZBfEnd - ZBfBeg) + ZBFEXP;
  547.             NewBuf = (charptr)ZRaloc(ZBfBeg, NewSiz);
  548.             if (NewBuf == NULL) {
  549.                 ErrMsg(ERR_MEM); /* MEM = memory overflow */
  550.                 DBGFEX(1,DbgFNm,"FAILURE, ZRaloc() failed");
  551.                 return (FAILURE);
  552.             }
  553.             ZBfRdP = NewBuf + (ZBfRdP - ZBfBeg);
  554.             ZBfEnd = NewBuf + NewSiz;
  555.             ZBfBeg = NewBuf;
  556.         }
  557. /*
  558.  * append a line from the EI file to ZBf
  559.  */
  560.  
  561.         if (ZRdLin(ZBfRdP,ZBfEnd-ZBfRdP,IfIndx,&line_len) == FAILURE) {
  562.             DBGFEX(1,DbgFNm,"FAILURE, ZRdLin() failed");
  563.             return (FAILURE);
  564.         }
  565.  
  566. /*
  567.  * break out of FOREVER loop if we tried reading past end of file.
  568.  */
  569.  
  570.         if (IsEofI[IfIndx]) {
  571.             DBGFMS(1,DbgFNm,"ran into EOF");
  572.             break;
  573.         }
  574.  
  575. #if DEBUGGING
  576.         sprintf(DbgSBf,"read %d bytes: \"%.*s\"",
  577.             (int)line_len, (int)line_len, ZBfRdP);
  578.         DbgFMs(1,DbgFNm,DbgSBf);
  579. #endif
  580.  
  581. /*
  582.  * go through the line we've read, looking for $$.
  583.  */
  584.  
  585.         TmpPtr = ZBfRdP;
  586.         ZBfRdP += line_len;
  587.         previous_char_was_escape = FALSE;
  588.         for (; TmpPtr < ZBfRdP; ++TmpPtr) {
  589.             if (*TmpPtr == ESCAPE) {
  590.                 if (previous_char_was_escape) {
  591.                     *ZBfPtr = ZBfRdP;
  592.                     *EscPtr = ++TmpPtr;
  593.                     DBGFEX(1,DbgFNm,
  594.                            "SUCCESS, ran into $$");
  595.                     return (SUCCESS);
  596.                 }
  597.                 previous_char_was_escape = TRUE;
  598.             } else {
  599.                 previous_char_was_escape = FALSE;
  600.             }
  601.         }
  602.     }
  603.  
  604.     *ZBfPtr = ZBfRdP;
  605.     *EscPtr = NULL;
  606.  
  607.     DBGFEX(1,DbgFNm,"SUCCESS");
  608.  
  609.     return SUCCESS;
  610. }
  611.  
  612. /*****************************************************************************
  613.  
  614.     OpnEI()
  615.  
  616.     This function opens an EI file.  The file name given by the user may
  617. find the file one of the following ways:
  618.  
  619.     1. as given (current directory)
  620.     2. as given, but with a ".TEC" type (current directory)
  621.     3. as given, in the default directory, with a ".TEC" type
  622.     3. as given, in the default directory
  623.  
  624. As soon as one of these forms is found and opened,  this function returns.
  625.  
  626. *****************************************************************************/
  627.  
  628. static DEFAULT OpnEI(EInd)    /* open an EI file */
  629. DEFAULT EInd;
  630. {
  631. #ifdef OPNEI_FINISHED
  632.     if (OpnInp(EInd, FALSE, TRUE) == SUCCESS)
  633.         return(SUCCESS);
  634.     if (OpnInp(EInd, TRUE, TRUE) == SUCCESS)
  635.         return(SUCCESS);
  636.     save contents of FBf
  637.     use :EGDEF command to fill FBf with default directory (how?)
  638.     append saved FBf to actual FBf
  639.     if (OpnInp(EInd, FALSE, TRUE) == SUCCESS)
  640.         return(SUCCESS);
  641.     if (OpnInp(EInd, TRUE, TRUE) == SUCCESS)
  642.         return(SUCCESS);
  643. #else
  644.     return OpnInp(EInd, TRUE, TRUE);
  645. #endif
  646. }
  647.  
  648. /*****************************************************************************
  649.  
  650.     DoEI()
  651.  
  652.     This function performs the execution part of an EI command.  It is
  653. called by the ExeEI function.  It is passed an index to a file data block in
  654. the IFiles array that has been opened.  It is also passed a memory buffer.
  655. This function reads text from the file into the buffer and calls ExeCSt to
  656. execute the text.
  657.  
  658. *****************************************************************************/
  659.  
  660. static DEFAULT DoEI(IfIndx)    /* do an EI command */
  661. DEFAULT    IfIndx;            /* index into IFiles array */
  662. {
  663.     charptr ZBfPtr;        /* pointer to end of command string in ZBf */
  664.     charptr EscPtr;        /* ptr into ZBf past second $ of $$ pair */
  665.     DEFAULT status;        /* return status of ExeCSt() */
  666.  
  667.     DBGFEN(1,"DoEI",NULL);
  668.  
  669.     status = SUCCESS;        /* in case we try doing an empty EI file */
  670.     ZBfRdP = ZBfBeg;        /* start reading into beginning of ZBf */
  671.     do {
  672. /*
  673.  * Read EI file into ZBf until $$ or EOF, whichever comes first
  674.  */
  675.     if (ReadEI(IfIndx, &ZBfPtr, &EscPtr) == FAILURE) {
  676.         ErrMsg(ERR_URE);        /* Unable to Read EI file */
  677.         DBGFEX(1,DbgFNm,"FAILURE, ReadEI() failed");
  678.         return FAILURE;
  679.     }
  680. /*
  681.  * save the current execution state and make ZBf the current command string
  682.  * to execute
  683.  */
  684.     if (PshMac(ZBfBeg, (EscPtr) ? EscPtr : ZBfPtr) == FAILURE) {
  685.         DBGFEX(1,DbgFNm,"FAILURE, PshMac() failed");
  686.         return FAILURE;
  687.     }
  688. /*
  689.  * execute macro in ZBf
  690.  */
  691.     status = ExeCSt();
  692.  
  693. #if DEBUGGING
  694.     if (status == FAILURE) {
  695.         DbgFMs(1,DbgFNm,"ExeCSt() failed");
  696.     }
  697. #endif
  698. /*
  699.  * restore old execution state
  700.  */
  701.     if (PopMac() == FAILURE) {
  702.         DBGFEX(1,DbgFNm,"FAILURE, PopMac() failed");
  703.         return FAILURE;
  704.     }
  705. /*
  706.  * if we ran into an $$ that was in the middle of a line,  then we want to
  707.  * move it to the beginning of ZBf and append the rest of the EI file to
  708.  * it; otherwise, we'll just start reading into the beginning of ZBf.
  709.  */
  710.     if (EscPtr) {
  711.         ptrdiff_t LeftOver;
  712.  
  713.         LeftOver = ZBfPtr - EscPtr;
  714.         MEMMOVE(ZBfBeg, EscPtr, LeftOver);
  715.         ZBfRdP = ZBfBeg + LeftOver;
  716.     } else {
  717.         ZBfRdP = ZBfBeg;
  718.     }
  719.  
  720.     } while (!IsEofI[IfIndx] && !GotCtC && status != FAILURE);
  721.  
  722.     DBGFEX(1,DbgFNm,(status == FAILURE) ? "FAILURE" : "SUCCESS");
  723.  
  724.     return status;        /* return ExeCSt() status */
  725. }
  726.  
  727. /*****************************************************************************
  728.  
  729.     ExeEI()
  730.  
  731.     This function executes an EI command.  This function does only part of
  732. the work;  the DoEI function does the rest.  This function opens/closes the
  733. file and allocates/deallocates an input buffer.  The code executes such that
  734. no matter what happens,  an open file will always be closed and allocated
  735. memory will always be freed.
  736.  
  737.     EI        Close current indirect command file
  738.     EIfilespec$    Open indirect command file
  739.  
  740. *****************************************************************************/
  741.  
  742. /*
  743.  * EIIndx is an index into the IFiles array.  It is incremented each time an
  744.  * EI command is executed and decremented each time an EI command completes.
  745.  * It is the index of the file data block of the currently open EI input file.
  746.  * When EIIndx equals EIFL-1,  no EI files are open.
  747.  */
  748.  
  749. static DEFAULT EIIndx = EIFL-1;
  750.  
  751. static DEFAULT ExeEI()            /* execute an EI command */
  752. {
  753.     int    status;
  754.  
  755.     DBGFEN(1,"ExeEI",NULL);
  756.  
  757.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  758.     DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  759.     return FAILURE;
  760.     }
  761.  
  762.     if (FBfPtr == FBfBeg) {            /* if it's EI$ */
  763.     if (EIIndx >= EIFL) {            /* if EI file is open */
  764.         CmdMod = '\0';            /* clear modifiers flags */
  765.     }
  766.     EStTop = EStBot;            /* clear expression stack */
  767.     DBGFEX(1,DbgFNm,"SUCCESS");
  768.     return SUCCESS;
  769.     }
  770.  
  771.     if (++EIIndx > NIFDBS) {            /* If EI nesting too deep */
  772.     EIIndx--;
  773.     ErrMsg(ERR_MEM);            /* ERR_MEM=memory overflow */
  774.     DBGFEX(1,DbgFNm,"FAILURE, EI nested too deep");
  775.     return FAILURE;
  776.     }
  777.  
  778.     if (OpnEI(EIIndx) != SUCCESS) {        /* open EI file */
  779.     status = FAILURE;
  780.     } else {
  781.     ZBfBeg = (charptr)ZAlloc(ZBFINIT);    /* allocate input buffer */
  782.     if (ZBfBeg == NULL) {            /* if allocation failed */
  783.         ErrMsg(ERR_MEM);            /* MEM = memory overflow */
  784.         status = FAILURE;
  785.     } else {                /* else allocation ok */
  786.         ZBfEnd = ZBfBeg + ZBFINIT;
  787.         status = DoEI(EIIndx);
  788.         ZFree((voidptr)ZBfBeg);        /* free allocated memory */
  789.     }
  790.     ZIClos(EIIndx);
  791.     }
  792.     EIIndx--;                    /* decrement nesting count */
  793.     CmdMod = '\0';                /* clear modifiers flags */
  794.     EStTop = EStBot;                /* clear expression stack */
  795.  
  796.     DBGFEX(1,DbgFNm,"SUCCESS");
  797.  
  798.     return status;
  799. }
  800.  
  801. /*****************************************************************************
  802.  
  803.     ExeEK()
  804.  
  805.     This function executes an EK command.
  806.  
  807.     EK        Kill output file
  808.  
  809. *****************************************************************************/
  810.  
  811. static DEFAULT ExeEK()            /* execute an EK command */
  812. {
  813.     DBGFEN(1,"ExeEK",NULL);
  814.  
  815.     ZOClDe(CurOut);            /* close and delete output file */
  816.     CmdMod = '\0';            /* clear modifiers flags */
  817.     EStTop = EStBot;        /* clear expression stack */
  818.  
  819.     DBGFEX(1,DbgFNm,"SUCCESS");
  820.  
  821.     return SUCCESS;
  822. }
  823.  
  824. /*****************************************************************************
  825.  
  826.     ExeEN()
  827.  
  828.     This function executes an EN command.
  829.  
  830.     EN        Wildcard lookup
  831.     :EN        EN, return status
  832.     ENfilespec$    Preset wildcard lookup
  833.  
  834. *****************************************************************************/
  835.  
  836. static DEFAULT ExeEN()            /* execute an EN command */
  837. {
  838.     DBGFEN(1,"ExeEN",NULL);
  839.  
  840.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  841.         DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  842.         return FAILURE;
  843.     }
  844.  
  845.     if (FBfPtr == FBfBeg) {        /* if it's EN$ or :EN$ */
  846.         switch (ZSWild()) {
  847.         case FAILURE:
  848.             DBGFEX(1,DbgFNm,"FAILURE, ZSWild() failed");
  849.             return FAILURE;
  850.  
  851.         case FILENF:
  852.             if (CmdMod & COLON) {    /* if it's :EN */
  853.                 CmdMod = '\0';    /* clear modifiers flags */
  854.                 EStTop = EStBot;/* clear expression stack */
  855.                 DBGFEX(1,DbgFNm,"PushEx(0)");
  856.                 return PushEx(0L,OPERAND);
  857.             }
  858.             ErrStr(ERR_FNF, "");    /* file not found */
  859.             DBGFEX(1,DbgFNm,"FAILURE");
  860.             return FAILURE;
  861.  
  862.         case SUCCESS:
  863.             if (CmdMod & COLON) {    /* if it's :EN */
  864.                 CmdMod = '\0';    /* clear modifiers flags */
  865.                 DBGFEX(1,DbgFNm,"PushEx(-1)");
  866.                 return PushEx(-1L,OPERAND);
  867.             }
  868.             EStTop = EStBot;/* clear expression stack */
  869.             CmdMod = '\0';    /* clear modifiers flags */
  870.             DBGFEX(1,DbgFNm,"SUCCESS");
  871.             return SUCCESS;
  872.         }
  873.     }
  874.  
  875.     if (ZPWild() == FAILURE) {        /* preset wildcard filepsec */
  876.         DBGFEX(1,DbgFNm,"FAILURE, ZPWild() failed");
  877.         return FAILURE;
  878.     }
  879.  
  880.     EStTop = EStBot;            /* clear expression stack */
  881.     CmdMod = '\0';                /* clear modifiers flags */
  882.  
  883.     DBGFEX(1,DbgFNm,"SUCCESS");
  884.     return SUCCESS;
  885. }
  886.  
  887. /*****************************************************************************
  888.  
  889.     ExeEO()
  890.  
  891.     This function executes an EO command.  TECO-C's version numbers
  892. started at 100 and went up.  Other implementations of TECO have version
  893. numbers less than 100.
  894.  
  895.     EO        Version of TECO
  896.     nEO        Set TECO to function as version n
  897.  
  898. *****************************************************************************/
  899.  
  900. static DEFAULT ExeEO()            /* execute an EO command */
  901. {
  902.     return ((EStTop > EStBot)        /* is it nEO ? */
  903.         ? ExeNYI()                /* ...yes, not supported */
  904.         : PushEx((LONG)TVERSION,OPERAND));    /* ...no, return version */
  905. }
  906.  
  907. /*****************************************************************************
  908.  
  909.     ExeEP()
  910.  
  911.     This function executes an EP command.
  912.  
  913.     EP        Select secondary output stream
  914.  
  915. *****************************************************************************/
  916.  
  917. static DEFAULT ExeEP()            /* execute an EP command */
  918. {
  919.     DBGFEN(1,"ExeEP",NULL);
  920.  
  921.     CurInp = SINPFL;        /* select secondary input stream */
  922.     CmdMod = '\0';            /* clear modifiers flags */
  923.     EStTop = EStBot;        /* clear expression stack */
  924.  
  925.     DBGFEX(1,DbgFNm,"SUCCESS");
  926.     return SUCCESS;
  927. }
  928.  
  929. /*****************************************************************************
  930.  
  931.     ExeEPr()
  932.  
  933.     This function executes an E% command.
  934.  
  935.     E%qfilespec$    Write Q-register q into a file
  936.  
  937. *****************************************************************************/
  938.  
  939. static DEFAULT ExeEPr()            /* execute an E% command */
  940. {
  941.     BOOLEAN RepErr;            /* report errors? */
  942.  
  943.     DBGFEN(1,"ExeEPr",NULL);
  944.  
  945.     if (IncCBP() == FAILURE) {        /* move to char after % */
  946.         DBGFEX(1,DbgFNm,"FAILURE, IncCBP() failed");
  947.         return FAILURE;
  948.     }
  949.  
  950.     if (FindQR() == FAILURE) {        /* find q-register */
  951.         DBGFEX(1,DbgFNm,"FAILURE, FindQR() failed");
  952.         return FAILURE;
  953.     }
  954.  
  955.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  956.         DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  957.         return FAILURE;
  958.     }
  959.  
  960.     if (FBfPtr == FBfBeg) {            /* if it's E%q$ */
  961.         ErrUTC();            /* unterminated command */
  962.         DBGFEX(1,DbgFNm,"FAILURE, unterminated command");
  963.         return FAILURE;
  964.     }
  965.  
  966.     RepErr = !(CmdMod & COLON);
  967.     CmdMod = '\0';
  968.     if (OpnOut(EPRCFL, RepErr) == FAILURE) {
  969. #if DEBUGGING
  970.         sprintf(DbgSBf,"%s, OpnOut() failed",
  971.             (RepErr) ? "FAILURE" : "PushEx(0)");
  972.         DbgFEx(1,DbgFNm,DbgSBf);
  973. #endif
  974.         return ((RepErr) ? FAILURE : PushEx(0L,OPERAND));
  975.     }
  976.  
  977.     if (QR->Start != NULL) {        /* if it's not empty */
  978.         if (ZWrBfr(EPRCFL, QR->Start, QR->End_P1-1) == FAILURE) {
  979. #if DEBUGGING
  980.             sprintf(DbgSBf,"%s, ZWrBfr() failed",
  981.                 (RepErr) ? "FAILURE" : "PushEx(0)");
  982.             DbgFEx(1,DbgFNm,DbgSBf);
  983. #endif
  984.             return ((RepErr) ? FAILURE : PushEx(0L,OPERAND));
  985.         }
  986.     }
  987.  
  988.     ZOClos(EPRCFL);                /* close the file */
  989.  
  990.     if (!RepErr) {
  991.         DBGFEX(1,DbgFNm,"PushEx(-1)");
  992.         return PushEx(-1L,OPERAND);
  993.     }
  994.  
  995.     EStTop = EStBot;            /* clear expression stack */
  996.  
  997.     DBGFEX(1,DbgFNm,"SUCCESS");
  998.     return SUCCESS;
  999. }
  1000.  
  1001. /*****************************************************************************
  1002.  
  1003.     ExeEQ()
  1004.  
  1005.     This function executes an EQ command.  The EQ command reads a file
  1006. directly into a q-register.  This command uses the RdPage function to
  1007. temporarily append the contents of the file to the end of the edit buffer.
  1008. It then copies the text to a q-register.
  1009.  
  1010.     EQqfilespec$    Read file into Q-register q
  1011.  
  1012. *****************************************************************************/
  1013.  
  1014. static DEFAULT ExeEQ()            /* execute an EQ command */
  1015. {
  1016.     ptrdiff_t    FSize;        /* file size */
  1017.     LONG        SvFFPg;        /* saved FFPage value */
  1018.     DEFAULT        SvCrIn;        /* saved CurInp value */
  1019.     ptrdiff_t    SvEbSz;        /* saved edit buffer size */
  1020.     DEFAULT        Status;
  1021.  
  1022.     DBGFEN(1,"ExeEQ",NULL);
  1023.  
  1024.     if (IncCBP() == FAILURE) {        /* move to char after Q */
  1025.         DBGFEX(1,DbgFNm,"FAILURE, IncCBP() failed");
  1026.         return FAILURE;
  1027.     }
  1028.  
  1029.     if (FindQR() == FAILURE) {
  1030.         DBGFEX(1,DbgFNm,"FAILURE, FindQR() failed");
  1031.         return FAILURE;
  1032.     }
  1033.  
  1034.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  1035.         DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  1036.         return FAILURE;
  1037.     }
  1038.  
  1039.     if (FBfPtr == FBfBeg) {            /* if it's EQq$ */
  1040.         ErrUTC();            /* unterminated command */
  1041.         DBGFEX(1,DbgFNm,"FAILURE, unterminated command");
  1042.         return FAILURE;
  1043.     }
  1044.  
  1045.     if (OpnInp(EQFL, FALSE, TRUE) != SUCCESS) {    /* open the file */
  1046.         DBGFEX(1,DbgFNm,"FAILURE, OpnInp() failed");
  1047.         return FAILURE;
  1048.     }
  1049.  
  1050. /*
  1051.  * We borrow RdPage's ability to read files correctly.  RdPage reads file
  1052.  * CurInp,  so we need to temporarily set CurInp to the EQ file data block.
  1053.  * The data is appended to the edit buffer,  so we need to save the pointer
  1054.  * to the current end of the edit buffer.
  1055.  */
  1056.     SvCrIn = CurInp;                /* save CurInp */
  1057.     SvEbSz = (EBfEnd - EBfBeg) - (GapEnd - GapBeg);    /* save EBfEnd */
  1058.     SvFFPg = FFPage;                /* save FFPage */
  1059.     CurInp = EQFL;
  1060.     do {
  1061.         if (RdPage() == FAILURE) {
  1062.             Status = FAILURE;
  1063.             goto exeeqdone;
  1064.         }
  1065.     } while (!IsEofI[EQFL]);
  1066.  
  1067. /*
  1068.  * Make room in the q-register.
  1069.  */
  1070.     FSize = EBfEnd - (EBfBeg + SvEbSz + (GapEnd - GapBeg));
  1071.     if (MakRom((SIZE_T)FSize) == FAILURE) {
  1072.         Status = FAILURE;
  1073.         goto exeeqdone;
  1074.     }
  1075.  
  1076. /*
  1077.  * Copy the text that we just read from the file into the q-register.
  1078.  */
  1079.     MEMMOVE(QR->Start,
  1080.         EBfBeg + SvEbSz + 1 + (GapEnd - GapBeg),
  1081.         (SIZE_T)FSize);
  1082.     QR->End_P1 = QR->Start + FSize;
  1083.  
  1084.     Status = SUCCESS;
  1085. exeeqdone:
  1086.     FFPage = SvFFPg;            /* restore FFpage */
  1087.     EBfEnd = EBfBeg + SvEbSz +
  1088.          (GapEnd - GapBeg);        /* restore EBfEnd */
  1089.     CurInp = SvCrIn;            /* restore CurInp */
  1090.  
  1091.     ZIClos(EQFL);                /* close the file */
  1092.  
  1093.     CmdMod = '\0';                /* clear modifiers flags */
  1094.     EStTop = EStBot;            /* clear expression stack */
  1095.  
  1096.     DBGFEX(1,DbgFNm,(Status == SUCCESS) ? "SUCCESS" : "FAILURE");
  1097.     return Status;
  1098. }
  1099.  
  1100. /*****************************************************************************
  1101.  
  1102.     ExeER()
  1103.  
  1104.     This function executes an ER command.
  1105.  
  1106.     ER        Select primary input stream
  1107.     ERfilespec$    Open input file
  1108.     :ERfilespec$    ER, return status
  1109. *****************************************************************************/
  1110.  
  1111. static DEFAULT ExeER()            /* execute an ER command */
  1112. {
  1113.     BOOLEAN    RepFNF;            /* report "file not found" errors? */
  1114.     DEFAULT    status;
  1115.  
  1116.     DBGFEN(1,"ExeER",NULL);
  1117.  
  1118.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  1119.         DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  1120.         return FAILURE;
  1121.     }
  1122.  
  1123.     if (FBfPtr == FBfBeg) {            /* if it's ER$ */
  1124.         CurInp = PINPFL;        /* primary input stream */
  1125.         CmdMod = '\0';            /* clear modifiers flags */
  1126.         EStTop = EStBot;        /* clear expression stack */
  1127.         DBGFEX(1,DbgFNm,"SUCCESS");
  1128.         return SUCCESS;
  1129.     }
  1130.  
  1131.     RepFNF = !(CmdMod & COLON);        /* report file not found? */
  1132.     CmdMod = '\0';                /* clear modifiers flags */
  1133.     status = OpnInp(CurInp, FALSE, RepFNF);    /* open input file */
  1134.     if (status != SUCCESS) {
  1135.         if (status == FILENF) {
  1136.             if (!RepFNF) {        /* if it's :ER */
  1137.                 DBGFEX(1,DbgFNm,"PushEx(0)");
  1138.                 return PushEx(0L,OPERAND);
  1139.             }
  1140.         }
  1141.         DBGFEX(1,DbgFNm,"FAILURE, OpnInp() failed");
  1142.         return FAILURE;
  1143.     }
  1144.  
  1145.     if (!RepFNF) {                /* if it's :ER */
  1146.         DBGFEX(1,DbgFNm,"PushEx(-1)");
  1147.         return PushEx(-1L,OPERAND);
  1148.     }
  1149.  
  1150.     EStTop = EStBot;            /* clear expression stack */
  1151.  
  1152.     DBGFEX(1,DbgFNm,"SUCCESS");
  1153.     return SUCCESS;
  1154. }
  1155.  
  1156. /*****************************************************************************
  1157.  
  1158.     ExeES()
  1159.  
  1160.     This function executes an ES command.
  1161.  
  1162.     ES        Search verification flag
  1163.  
  1164. *****************************************************************************/
  1165.  
  1166. static DEFAULT ExeES()            /* execute an ES command */
  1167. {
  1168.     DBGFEN(1,"ExeES",NULL);
  1169.     DBGFEX(1,DbgFNm,"DoFlag(&EsFlag)");
  1170.     return DoFlag(&EsFlag);
  1171. }
  1172.  
  1173. /*****************************************************************************
  1174.  
  1175.     ExeET()
  1176.  
  1177.     This function executes an ET command.
  1178.  
  1179.     ET        Type out control flag
  1180.  
  1181. *****************************************************************************/
  1182.  
  1183. static DEFAULT ExeET()            /* execute an ET command */
  1184. {
  1185.         DEFAULT status;
  1186.         WORD TmpET;
  1187.  
  1188.     DBGFEN(1,"ExeET",NULL);
  1189.  
  1190.     TmpET = EtFlag;
  1191.     status = DoFlag(&EtFlag);
  1192.  
  1193. /*
  1194.  * If DoFlag set or cleared the 8-bit flag,  we have to tell the operating
  1195.  * system.
  1196.  */
  1197.     if (status != FAILURE) {
  1198.         if ((TmpET & ET_EIGHTBIT) &&      /* eightbit flag cleared? */
  1199.         !(EtFlag & ET_EIGHTBIT)) {
  1200.         status = ZSetTT(TT8BIT, 0);
  1201.         } else if (!(TmpET & ET_EIGHTBIT) &&  /* eightbit flag set? */
  1202.         (EtFlag & ET_EIGHTBIT)) {
  1203.         status = ZSetTT(TT8BIT, 1);
  1204.         }
  1205.     }
  1206.  
  1207. /*
  1208.  * If one of the read-only flags was changed,  set it back.
  1209.  */
  1210.     if ((TmpET & ET_WAT_SCOPE) != (EtFlag & ET_WAT_SCOPE)) {
  1211.         if (TmpET & ET_WAT_SCOPE)        /* if it was cleared */
  1212.         EtFlag |= ET_WAT_SCOPE;        /* set it */
  1213.         else
  1214.         EtFlag &= ~ET_WAT_SCOPE;    /* clear it */
  1215.     }
  1216.     if ((TmpET & ET_WAT_REFRESH) != (EtFlag & ET_WAT_REFRESH)) {
  1217.         if (TmpET & ET_WAT_REFRESH)        /* if it was cleared */
  1218.         EtFlag |= ET_WAT_REFRESH;    /* set it */
  1219.         else
  1220.         EtFlag &= ~ET_WAT_REFRESH;    /* clear it */
  1221.     }
  1222.  
  1223.     DBGFEX(1,DbgFNm,(status==FAILURE) ? "FAILURE" : "SUCCESS");
  1224.     return status;
  1225. }
  1226.  
  1227. /*****************************************************************************
  1228.  
  1229.     ExeEU()
  1230.  
  1231.     This function executes an EU command.
  1232.  
  1233.     EU        Case flagging flag
  1234.  
  1235. *****************************************************************************/
  1236.  
  1237. static DEFAULT ExeEU()            /* execute an EU command */
  1238. {
  1239.     DBGFEN(1,"ExeEU",NULL);
  1240.     DBGFEX(1,DbgFNm,"DoFlag(&EuFlag)");
  1241.     return DoFlag(&EuFlag);
  1242. }
  1243.  
  1244. /*****************************************************************************
  1245.  
  1246.     ExeEUn()
  1247.  
  1248.     This function executes an E_ command.
  1249.  
  1250.     nE_        Search without yank protection
  1251.  
  1252. *****************************************************************************/
  1253.  
  1254. static DEFAULT ExeEUn()            /* execute an E_ command */
  1255. {
  1256.     DBGFEN(1,"ExeEUn",NULL);
  1257.  
  1258. /*
  1259.  * The command m,nE_ is illegal: the user should use m,nFB
  1260.  */
  1261.  
  1262.     if (CmdMod & MARGIS) {            /* if it's m,nE_ */
  1263.         ErrStr(ERR_ILL, "m,nE_");    /* illegal command "m,nE_" */
  1264.         DBGFEX(1,DbgFNm,"FAILURE, m,nE is illegal");
  1265.         return FAILURE;
  1266.     }
  1267.  
  1268.     if (CmdMod & DCOLON) {            /* if it's ::E_ */
  1269.         ErrStr(ERR_ILL, "::E_");    /* illegal command "::E_" */
  1270.         DBGFEX(1,DbgFNm,"FAILURE, ::E_ is illegal");
  1271.         return FAILURE;
  1272.     }
  1273.  
  1274.     SrcTyp = E_SEARCH;
  1275.     if (Search(FALSE) == FAILURE) {
  1276.         DBGFEX(1,DbgFNm,"FAILURE, Search() failed");
  1277.         return FAILURE;
  1278.     }
  1279.  
  1280.     CmdMod = '\0';                /* clear modifiers flags */
  1281.  
  1282.     DBGFEX(1,DbgFNm,"SUCCESS");
  1283.     return SUCCESS;
  1284. }
  1285.  
  1286. /*****************************************************************************
  1287.  
  1288.     ExeEV()
  1289.  
  1290.     This function executes an EV command.
  1291.  
  1292.     EV        Edit verify flag
  1293.  
  1294. *****************************************************************************/
  1295.  
  1296. static DEFAULT ExeEV()            /* execute an EV command */
  1297. {
  1298.     DBGFEN(1,"ExeEV",NULL);
  1299.     DBGFEX(1,DbgFNm,"DoFlag()");
  1300.     return DoFlag(&EvFlag);
  1301. }
  1302.  
  1303. /*****************************************************************************
  1304.  
  1305.     ExeEW()
  1306.  
  1307.     This function executes an EW command.
  1308.  
  1309.     EWfilespec$    Open output file
  1310.     EW        Select primary output stream
  1311.  
  1312. *****************************************************************************/
  1313.  
  1314. static DEFAULT ExeEW()            /* execute an EW command */
  1315. {
  1316.     BOOLEAN RepErr;            /* report errors? */
  1317.  
  1318.     DBGFEN(1,"ExeEW",NULL);
  1319.  
  1320.     if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE) {
  1321.         DBGFEX(1,DbgFNm,"FAILURE, BldStr() failed");
  1322.         return FAILURE;
  1323.     }
  1324.  
  1325.     if (FBfPtr == FBfBeg) {            /* if it's EW$ */
  1326.         CmdMod = '\0';            /* clear modifiers flags */
  1327.         CurOut = POUTFL;        /* primary output stream */
  1328.         EStTop = EStBot;        /* clear expression stack */
  1329.         DBGFEX(1,DbgFNm,"SUCCESS");
  1330.         return SUCCESS;
  1331.     }
  1332.  
  1333.     RepErr = !(CmdMod & COLON);
  1334.     CmdMod = '\0';                /* clear modifiers flags */
  1335.     if (OpnOut(CurOut, RepErr) == FAILURE) {
  1336. #if DEBUGGING
  1337.         sprintf(DbgSBf,"%s, OpnOut() failed",
  1338.             (RepErr) ? "FAILURE" : "PushEx(0)");
  1339.         DbgFEx(1,DbgFNm,DbgSBf);
  1340. #endif
  1341.         return ((RepErr) ? FAILURE : PushEx(0L,OPERAND));
  1342.     }
  1343.  
  1344.     if (!RepErr) {
  1345.         DBGFEX(1,DbgFNm,"PushEx(-1)");
  1346.         return PushEx(-1L,OPERAND);
  1347.     }
  1348.  
  1349.     EStTop = EStBot;        /* clear expression stack */
  1350.  
  1351.     DBGFEX(1,DbgFNm,"SUCCESS");
  1352.     return SUCCESS;
  1353. }
  1354.  
  1355. /*****************************************************************************
  1356.  
  1357.     ExeEX()
  1358.  
  1359.     This function executes an EX command.
  1360.  
  1361.     EX        Close out and exit
  1362.  
  1363. *****************************************************************************/
  1364.  
  1365. static DEFAULT ExeEX()            /* execute an EX command */
  1366. {
  1367.     DBGFEN(1,"ExeEX",NULL);
  1368.  
  1369.     if (ExeEC() != FAILURE) {        /* execute an EC command */
  1370.         DBGFEX(1,DbgFNm,"exiting successfully!");
  1371.         TAbort(EXIT_SUCCESS);        /* exit TECO-C */
  1372.     }
  1373.  
  1374.     DBGFEX(1,DbgFNm,"FAILURE, ExeEX() failed");
  1375.     return FAILURE;
  1376. }
  1377.  
  1378. /*****************************************************************************
  1379.  
  1380.     ExeEZ()
  1381.  
  1382.     This function executes an EZ command.  EZ is a mode control flag
  1383. that contains bits specific to the operating system we're using.
  1384.  
  1385. *****************************************************************************/
  1386.  
  1387. static DEFAULT ExeEZ()            /* execute an EZ command */
  1388. {
  1389.     DBGFEN(1,"ExeEZ",NULL);
  1390.     DBGFEX(1,DbgFNm,"DoFlag(&EZFlag)");
  1391.     return DoFlag(&EzFlag);
  1392. }
  1393.  
  1394. /*****************************************************************************
  1395.  
  1396.     ExeE()
  1397.  
  1398.     This function executes two-letter commands that start with "E".
  1399. It uses the character following the "E" to index into a table of functions.
  1400.  
  1401. *****************************************************************************/
  1402.  
  1403. DEFAULT    ExeE()                /* execute an E command */
  1404. {
  1405.     unsigned char TmpChr;
  1406.     static DEFAULT (*FEAray[])(VVOID) = {
  1407.         /* A */ ExeEA,    /* B */ ExeEB,
  1408.         /* C */ ExeEC,    /* D */ ExeED,
  1409.         /* E */ ExeIll,   /* F */ ExeEF,
  1410.         /* G */ ExeEG,    /* H */ ExeEH,
  1411.         /* I */ ExeEI,    /* J */ ZExeEJ,
  1412.         /* K */ ExeEK,    /* L */ ExeNYI,
  1413.         /* M */ ExeNYI,   /* N */ ExeEN,
  1414.         /* O */ ExeEO,    /* P */ ExeEP,
  1415.         /* Q */ ExeEQ,    /* R */ ExeER,
  1416.         /* S */ ExeES,    /* T */ ExeET,
  1417.         /* U */ ExeEU,    /* V */ ExeEV,
  1418.         /* W */ ExeEW,    /* X */ ExeEX,
  1419.         /* Y */ ExeEY,    /* Z */ ExeEZ
  1420.     };
  1421.  
  1422.     if (IncCBP() == FAILURE) {
  1423.         return FAILURE;
  1424.     }
  1425.  
  1426.     TmpChr = To_Upper (*CBfPtr);
  1427.  
  1428.     if (TmpChr == '%') {            /* we have E%q */
  1429.         return ExeEPr();
  1430.     }
  1431.  
  1432.     if (TmpChr == '_') {            /* we have nE_ */
  1433.         return ExeEUn();
  1434.     }
  1435.  
  1436.     if (!Is_Upper(TmpChr) || (TmpChr == 'E')) {
  1437.         ErrChr(ERR_IEC, TmpChr);
  1438.         return FAILURE;
  1439.     }
  1440.  
  1441.     return (*FEAray[TmpChr-'A'])();
  1442. }
  1443.